package com.flying.scorer.score.equity.quarterlyreport;


import com.flying.refdata.model.equity.EquityInfo;
import com.flying.refdata.model.equity.QuarterlyReport;
import com.flying.refdata.service.ReportService;
import com.flying.scorer.score.ScoreException;

public class RevenueGrowthRateVariationEquityScorer extends AbstractQuarterlyReportScorer {
    public RevenueGrowthRateVariationEquityScorer(ReportService reportService) {
        super(reportService);
    }

    @Override
    public double score(int date, EquityInfo info) throws ScoreException {
        QuarterlyReport current = getQuarterlyReport(info ,date);
        QuarterlyReport previous = getPreviousQuarterlyReport(current.getEquityInfo(), current.getYear() - 1, current.getQuarter());
        double variation = current.getRevenueGrowthRate() - previous.getRevenueGrowthRate();
        if (variation < 0) return 0;
        else if (variation > 10) return 10;
        else return Math.floor(variation);
    }
}
